package com.huluob.myapplication

import android.os.Handler
import com.huluobo.lc.kotlinim1803a.contract.SplashContract
import com.huluobo.lc.kotlinim1803a.contract.SplashPresenter
import org.jetbrains.anko.startActivity

class SplashActivity:BaseActivity(),SplashContract.View  {

    private val presenter = SplashPresenter(this)

    override fun init() {
        super.init()
        presenter.checkLoginStatus()
    }

    companion object {
        const val DELAY = 2000L
    }

    //委托给lazy,实现懒加载
    private val handler by lazy { //懒加载
        Handler()
    }

    override fun getLayoutResId(): Int = R.layout.activity_splash

    // * 1.如果没有登录,延时2秒,跳转到登录界面
    override fun onNotLoggedIn() {
        handler.postDelayed({
            startActivity<LoginActivity>()
            finish()
        }, DELAY)
    }

    // * 2.如果已经登录,则跳转到主页面
    override fun onLoggedIn() {
        startActivity<MainActivity>()
        finish()
    }
}